const path = require('path');

function resolve(dir) {
    return path.join(__dirname, '.', dir);
}
module.exports = {
    //兼容es6低版本浏览器
    chainWebpack: config => {
        config.module.rule('compile')
            .test(/\.js$/)
            .include
            .add(resolve('src'))
            .add(resolve('test'))
            .add(resolve('node_modules/webpack-dev-server/client'))
            .add(resolve('node_modules'))
            .end()
            .use('babel')
            .loader('babel-loader')
            .options({
                presets: [
                    ['@babel/preset-env', {
                        modules: false
                    }]
                ]
            });
    },
    pages:{
        index: {
            entry: 'src/main.js',
            // 当使用 title 选项时，
            // template 中的 title 标签需要是 <title><%= htmlWebpackPlugin.options.title %></title>
            title: process.env.VUE_APP_TITLE
        },
    },
    css: {
        loaderOptions: {
            stylus: {
                'resolve url': true,
                'import': [
                    './src/theme',
                    './src/common/css/variable.styl',
                    './src/common/css/icon.styl',
                    './src/common/css/index.styl'
                ]
            }
        }
    },
    pluginOptions: {
        'cube-ui': {
            postCompile: true,
            theme: true
        }
    },
    publicPath: process.env.NODE_ENV === 'production'
        ? process.env.VUE_APP_HEAD
        : '/'
}
